package com.sdweizan.sdk.bytedance.util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.Charsets;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.entity.StringEntity;

import java.util.Map;

@Slf4j
public class HttpClientPostRequestExecutor<T> extends HttpClientRequestExecutor<T> {

  public HttpClientPostRequestExecutor(TypeReference<T> typeReference) {
    super(typeReference);
  }

  @Override
  protected HttpRequestBase buildRequest(String requestUri, Map<String, Object> requestBody) {
    log.info("访问字节服务接口：{}", requestUri);
    HttpPost httpPost = new HttpPost(requestUri);
    String requestEntity = JSON.toJSONString(requestBody);
    log.info("访问字节服务接口请求报文：{}", requestEntity);
    httpPost.setEntity(new StringEntity(requestEntity, Charsets.UTF_8));
    return httpPost;
  }
}
